package com.yuan.dingtalk;

import com.yuan.dingtalk.service.DingtalkAppService;
import com.yuan.dingtalk.service.DingtalkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(DingtalkService.class)
@EnableConfigurationProperties(DingTalkProperties.class)
public class DingtalkConfiguration {

    @Autowired
    private DingTalkProperties dingTalkProperties;

    @Bean
    public DingtalkService dingtalkService(){
        return new DingtalkService(dingTalkProperties.getApiUrl(), dingTalkProperties.getCacheType());
    }

    @Bean
    public DingtalkAppService dingtalkAppService(){
       return new DingtalkAppService(dingTalkProperties.getApiUrl(), dingTalkProperties.getCorpId(),
               dingTalkProperties.getAgentId(), dingTalkProperties.getAppKey(), dingTalkProperties.getAppSecret());
    }
}
